/*
 * Copyright (c) 2023.11.29 Fengxun
 * Version:5.2.2
 */

const {
  getUserInfo,
  getBaseConfig,
  getPageConfig
} = require("../../utils/custom_loading");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    gold: 0,
    finishPercent: 0,
    finishCount: 2,
    totalCount: 0,
    processText: '',
    processImage: '',
    npcImageGongtou: '',
    processArray: [{
        /*0-9999，开不了工；9999-69999，小巧；70000-11999，稍具规模；12000-最大，颇具规模*/
        gold: -1,
        text: '暂时还开不了工。',
        image: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/progress0.png',
        npcImage: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/npcGongtou1.png'
      },
      {
        gold: 9999,
        text: '修了一座小巧的字库塔。',
        image: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/progress1.png',
        npcImage: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/npcGongtou2.png'
      },
      {
        gold: 69999,
        text: '建了一座稍有规模的字库塔。',
        image: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/progress2.png',
        npcImage: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/npcGongtou3.png'
      },
      {
        gold: 119999,
        text: '建了一座颇具规模的字库塔。',
        image: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/progress3.png',
        npcImage: 'https://6665-fengxun-9gayk1ftacc25e37-1258711681.tcb.qcloud.la/npcGongtou4.png'
      }
    ]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 初始化配置
    const config = getPageConfig('process')
    if (config) {
      this.setData({
        config
      })
    }

    let gold = wx.getStorageSync('gold')

    // 根据获取的金币判断输出文字和图像
    for (let index = 0; index < this.data.processArray.length; index++) {
      let processInfo = this.data.processArray[index]
      // console.log('processInfo', processInfo)
      if (gold > processInfo.gold) {
        this.setData({
          processText: processInfo.text,
          processImage: processInfo.image,
          npcImageGongtou: processInfo.npcImage
        })
      } else {
        break
      }
    }

    // 计算剩余关卡
    let totalCount = wx.getStorageSync('totalCount')
    let finishCount = wx.getStorageSync('finishCount')

    this.setData({
      gold,
      finishCount,
      totalCount,
      finishPercent: parseInt(finishCount * 100 / totalCount)
    })
  },

  resetGame() {
    wx.showModal({
      title: '提示',
      content: '你需要重新玩一次吗？',
      success(res) {
        if (res.confirm) {
          wx.clearStorage()
          wx.redirectTo({
            url: 'login',
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})